<?php defined('SYSPATH') or die('No direct script access.');
/**
* Language Support
*/
class Helper_LanguageSupport {
	
	static function &factory() {
	   $o = new Helper_LanguageSupport();
	  return $o;	
	}
	
  // Show Language Links
	public function language_link($views='text')
	{
		$ss	= Session::instance();
		$r	= Request::current();
		
		$languagequery = DB::select('language_key')
			->from('countrylists')
			->group_by('language_key')
			->order_by('position','ASC')
			->execute();
		$showflags = $languagequery->as_array();
		
		echo   "<div id='langFlag'>";
		
		// Show Active Language Text Now
		$languagenow = DB::select('language')
			->from('countrylists')
			->where('language_key','=',$ss->get('langid'))
			->limit(1)
			->execute();
		$show_active_language = $languagenow->as_array();
		
		switch ($views)
		{
		case "text":
				  // View Full Text
					echo 'active language : <strong>';
					
					if(empty($show_active_language))
					{
						echo 'none';
					} else {
					  echo $show_active_language[0]['language'];
					}
					
					echo '</strong> | change : ';
					break;
		
		case "simple":
				  // View Simple Text
					echo '<strong>';
					
					if(empty($show_active_language))
					{
						echo 'none';
					} else {
					  echo $show_active_language[0]['language'];
					}
					
					echo '</strong> | ';
					break;
		
		case "none":
					echo NULL;
					break;
		}
		
		// Loop The Language Flag
		foreach($showflags as $showflag)
		{
			$attrib = NULL;
						
			if($showflag['language_key'] == $ss->get('langid')) $attrib = array('style'=>'margin-bottom: -6px; border-bottom:2px solid;');
				echo HTML::anchor($r->uri2().URL::query(array('lang'=>$showflag['language_key'])), HTML::image('assets/global/images/language_flag/flag_'.$showflag['language_key'].'.png', $attrib));
				echo '&nbsp;&nbsp;';
		}
		
		echo   "</div>";
	}
	
  // Set New Language
	public function set_new_language($new_language)
	{
		$ss	= Session::instance();
		
		$ss->set('langid',$new_language);
	}
	
	
	
	
	
	
	
	
	
}




